<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>paste</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_1631">&nbsp;</a>NAME</h4><blockquote>
paste - merge corresponding or subsequent lines of files
</blockquote><h4><a name = "tag_001_014_1632">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

paste <b>[</b>-s<b>][</b>-d <i>list</i><b>] </b><i>file</i>...
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_1633">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>paste</i>
utility will concatenate the corresponding lines
of the given input files, and write the resulting lines to standard output.
<p>
The default operation of
<i>paste</i>
will concatenate the corresponding lines of the input files.
The
newline
character of every line except the
line from the last input file will be replaced with a
tab
character.
<p>
If an end-of-file condition is detected on one or more input
files, but not all input files,
<i>paste</i>
will behave as though
empty lines were read from the files on which end-of-file was
detected, unless the
<b>-s</b>
option is specified.
</blockquote><h4><a name = "tag_001_014_1634">&nbsp;</a>OPTIONS</h4><blockquote>
The
<i>paste</i>
utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .
<p>
The following options are supported:
<dl compact>

<dt><b>-d&nbsp;</b><i>list</i>
<dd>Unless a backslash character appears in
<i>list</i>,
each character in
<i>list</i>
is an element specifying a delimiter character.
If a backslash character appears in
<i>list</i>,
the backslash character and one or more characters following
it are an element specifying a delimiter character as described below.
These elements specify one or more delimiters
to use, instead of the default
tab character,
to replace the
newline
character of
the input lines.
The elements in
<i>list</i>
are used circularly; that is,
when the list is exhausted the first
element from the list is reused.
When the
<b>-s</b>
option is specified:
<ul>

<li>
The last
newline
character in a file will not be modified.

<li>
The delimiter will be reset
to the first element of list after each
<i>file</i>
operand is processed.

</ul>

When the
<b>-s</b>
option is not specified:
<ul>

<li>
The
newline
characters in the file
specified by the last
<i>file</i>
operand will not be modified.

<li>
The delimiter
will be reset to the first element of list each time a line is
processed from each file.

</ul>

If a backslash character appears in
<i>list</i>,
it and the character following it will be used to
represent the following delimiter characters:
<dl compact>

<dt><b>\n</b><dd>Newline character.

<dt><b>\t</b><dd>Tab character.

<dt><b>\\</b><dd>Backslash character.

<dt><b>\0</b><dd>Empty string (not a null character).
If
\0
is immediately followed by the character
x,
the character
X,
or any character defined by the LC_CTYPE
<b>digit</b>
keyword (see
the <b>XBD</b> specification, <a href="../xbd/locale.html"><b>Locale</b>&nbsp;</a> ),
the results are unspecified.

</dl>
<p>
If any other characters follow the backslash, the results are unspecified.
<br>
<br>
<dt><b>-s</b>
<dd>Concatenate all of the lines
of each separate input file in command line order.
The
newline
character of every line except the last line in
each input file will be replaced with the
tab
character, unless otherwise specified by the
<b>-d</b>
option.
<p>
</dl>
</blockquote><h4><a name = "tag_001_014_1635">&nbsp;</a>OPERANDS</h4><blockquote>
The following operand is supported:
<dl compact>

<dt><i>file</i><dd>A pathname of an input file.
If "-" is specified for one or more of the
<i>file</i>s,
the standard input will be used;
the standard input will be read one line at
a time, circularly, for each instance of "-".
Implementations support pasting of at least 12
<i>file</i>
operands.

</dl>
</blockquote><h4><a name = "tag_001_014_1636">&nbsp;</a>STDIN</h4><blockquote>
The standard input will be used only if one or more
<i>file</i>
operands is "-".
See the INPUT FILES section.
</blockquote><h4><a name = "tag_001_014_1637">&nbsp;</a>INPUT FILES</h4><blockquote>
The input files must be text files,
except that line lengths will be unlimited.
</blockquote><h4><a name = "tag_001_014_1638">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>paste</i>:
<dl compact>

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.

<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.

<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data as
characters (for example, single- as opposed to multi-byte characters
in arguments and input files).

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
</dl>
</blockquote><h4><a name = "tag_001_014_1639">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_1640">&nbsp;</a>STDOUT</h4><blockquote>
Concatenated lines of input files will be separated by the
tab
character (or other characters under the control of the
<b>-d</b>
option) and terminated by a
newline
character.
</blockquote><h4><a name = "tag_001_014_1641">&nbsp;</a>STDERR</h4><blockquote>
Used only for diagnostic messages.
</blockquote><h4><a name = "tag_001_014_1642">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_1643">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
None.
<br>
</blockquote><h4><a name = "tag_001_014_1644">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>Successful completion.

<dt>&gt;0<dd>An error occurred.

</dl>
</blockquote><h4><a name = "tag_001_014_1645">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
If one or more input files cannot be opened when the
<b>-s</b>
option is not specified, a diagnostic message will be written to
standard error, but no output will be written to standard output.
If the
<b>-s</b>
option is specified, the
<i>paste</i>
utility will provide the default behaviour described in
<a href="utildes.html">Utility Description Defaults</a>
<xref href=utildes></xref>.
</blockquote><h4><a name = "tag_001_014_1646">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
When the escape sequences of the
<i>list</i>
option-argument are used in a shell script, they must be quoted;
otherwise, the shell treats the
\
as a special character.
<p>
Portable applications should only use the specific
backslash escaped delimiters presented in this specification.
Historical implementations treat
\x,
where
x
is not in this list, as
x,
but future implementations
are free to expand this list to recognise other common escapes
similar to those accepted by
<i><a href="printf.html">printf</a></i>
and other standard utilities.
<p>
Most of the standard utilities work on text files.
The
<i><a href="cut.html">cut</a></i>
utility can be used to turn files with arbitrary line lengths
into a set of text files containing the same data.
The
<i>paste</i>
utility can be used to create (or recreate) files with arbitrary
line lengths.
For example, if
<b>file</b>
contains long lines:
<pre>
<code>
cut -b 1-500 -n file &gt; file1
cut -b 501- -n file &gt; file2
</code>
</pre>
creates
<b>file1</b>
(a text file) with lines no longer than 500 bytes
(plus the newline character) and
<b>file2</b>
that contains the remainder of the data from
<b>file</b>.
Note that
file2
will not be a text file if there are lines in file that are longer than 500 +
{LINE_MAX}
bytes.
The original file can be recreated from
<b>file1</b>
and
<b>file2</b>
using the command:
<pre>
<code>
paste -d "\0" file1 file2 &gt; file
</code>
</pre>
<p>
The commands:
<pre>
<code>
paste -d "\0" ...
paste -d "" ...
</code>
</pre>
are not necessarily equivalent;
the latter is not specified by this specification and may result in an error.
The construct
\0
is used to mean &quot;no separator&quot; because
historical versions of
<i>paste</i>
did not follow the syntax guidelines, and the command:
<pre>
<code>
paste -d"" ...
</code>
</pre>
could not be handled properly by
<i><a href="../xsh/getopt.html">getopt()</a></i>.
</blockquote><h4><a name = "tag_001_014_1647">&nbsp;</a>EXAMPLES</h4><blockquote>
<ol>
<p>
<li>
Write out a directory in four columns:
<pre>
<code>
ls | paste - - - -
</code>
</pre>
<p>
<li>
Combine pairs of lines from a file into single lines:
<pre>
<code>
paste -s -d "\t\n" file
</code>
</pre>
<p>
</ol>
</blockquote><h4><a name = "tag_001_014_1648">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_1649">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="cut.html">cut</a></i>,
<i><a href="grep.html">grep</a></i>,
<i><a href="pr.html">pr</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
